package org.emet.entity.biz;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.emet.jee.console.entity.BaseEntity;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 * 4、礼仪仪式：是在殡仪馆举行的各种礼仪，如接灵仪式、入灵仪式、司仪主持、礼仪入炉等。
 */
@Entity
@Table(name = "T_CEREMONY")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Ceremony extends BaseEntity {
	private Registration reg;
	private String type;
	private BigDecimal fee;
	private Boolean paied = false;
	private Date startDate;
	private Date endDate;
	private List<Employee> workers;

	public Boolean isPaied() {
		return paied;
	}

	public void setPaied(Boolean paied) {
		this.paied = paied;
	}

	@ManyToOne(targetEntity = Registration.class)
	@Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE })
	@JoinColumn(name = "reg_id")
	public Registration getReg() {
		return reg;
	}

	public void setReg(Registration reg) {
		this.reg = reg;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public BigDecimal getFee() {
		return fee;
	}

	public void setFee(BigDecimal fee) {
		this.fee = fee;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name = "T_CEREMONY_EMPLOYEE", joinColumns = { @JoinColumn(name = "CEREMONY_ID") }, inverseJoinColumns = { @JoinColumn(name = "EMPLOYEE_ID") })
	@Fetch(FetchMode.SUBSELECT)
	@OrderBy("id")
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public List<Employee> getWorkers() {
		return workers;
	}

	public void setWorkers(List<Employee> workers) {
		this.workers = workers;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
}
